package com;

import tool.jdbctool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

@WebServlet(name = "corefind")
public class corefind extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out=response.getWriter();
        Connection connection=null;
        HttpSession session=request.getSession();
        session.getAttribute("userid");
        PreparedStatement statement=null;
        String core=null;
        ResultSet resultSet=null;
        try {
            connection= jdbctool.getconection();
            statement=connection.prepareStatement(
                    "select `core` from`users`where `userid`=?");
            statement.setString(1, String.valueOf(session.getAttribute("userid")));
            resultSet=statement.executeQuery();
            while (resultSet.next())
            core=resultSet.getString(1);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            jdbctool.close(connection,statement,resultSet);
        }
        if (core==null)
        out.write("<center><font style=\"color: red;font-size: 40px\">当前无成绩</font></center>");
        else
        {
            out.write("<center><font style=\"color: red;font-size: 40px\">"+core+"</font></center>");
        }
    }
}
